#include "functiongenerator.h"

int CFunctionGenerator::get_random_int(int max)
{
    return rand() % max;
}

int CFunctionGenerator::get_random_int(int min, int max)
{
    return rand() % (max - min) + min;
}

void CFunctionGenerator::get_random_str(char* buffer, int str_length, bool is_add_zero)
{
    size_t i = 0;
    for (; i < str_length; i++)
    {
        buffer[i] = CHAR_TABLE[get_random_int(sizeof(CHAR_TABLE) / sizeof(CHAR_TABLE[0]))];
    }
    if (is_add_zero)
    {
        buffer[i] = 0;
    }
}

void CFunctionGenerator::get_random_var_name(char* buffer, int str_length, bool is_add_zero)
{
    char first_char;
    while ( first_char = CHAR_TABLE[get_random_int(sizeof(CHAR_TABLE) / sizeof(CHAR_TABLE[0]))])
    {
        if (first_char >= '0' && first_char <= '9')
        {
            continue;
        }
        break;
    }
    buffer[0] = first_char;

    size_t i = 1;
    for (; i < str_length; i++)
    {
        buffer[i] = CHAR_TABLE[get_random_int(sizeof(CHAR_TABLE) / sizeof(CHAR_TABLE[0]))];
    }
    if (is_add_zero)
    {
        buffer[i] = 0;
    }
}
